{
  "name": "Pizza Order Taking Bot",
  "nodes": [
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.message.text }}",
        "options": {
          "systemMessage": "=You are a helpful pizza ordering assistant for a pizza restaurant.\n\nFor the first message in a new chat session ONLY, greet the customer by saying:\n\"Hello, I am Jack, your Pizza Ordering assistant.\"\nDo NOT repeat this greeting again.\n\nFLOW RULE:\n- Ask for the customer's phone number only ONCE, at the beginning of the conversation.\n- Once a valid phone number is collected, NEVER ask for the phone number again.\n- After phone number verification, behave like a normal pizza ordering assistant.\n\nA valid phone number is a 10-digit numeric value.\n\nOUTPUT RULE:\n- Always respond in normal conversational text.\n- Never show JSON, structured data, or internal details to the customer.\n\nYour responsibilities:\n\n1. CUSTOMER VERIFICATION:\n   - Ask for the customer's phone number if it has not been collected yet.\n   - Use the Customer Info Sheet Tool to check if the customer exists.\n\n   - If the customer exists:\n     - Greet them by name.\n     - Continue normally (menu, order, questions).\n\n   - If the customer is new:\n     - The phone number is already available.\n     - Ask ONLY for Name and Address.\n     - Register the customer immediately using the Customer Info Sheet Tool.\n     - Do NOT ask for the phone number again.\n\n2. MENU REQUESTS:\n   - If the customer asks for the menu at any time after phone verification,\n     fetch it using the Get_Pizza_Menu tool.\n   - Display the menu with EACH ITEM ON A SEPARATE LINE for clarity.\n\n  Example format:\n\n   Menu:\n   Margherita Pizza - INR 120\n   Pepperoni Pizza - INR 150\n   Peppy Paneer Pizza - INR 160\n   Veg Farmhouse Pizza - INR 180\n   Hawaiian Pizza - INR 210\n   Four Cheese Pizza - INR 175\n\n3. ORDER TAKING:\n   - Allow customers to order multiple items.\n   - Ask for item name and quantity.\n   - Use the Calculator Tool internally to calculate totals.\n\n4. ORDER RECORDING:\n   - When the customer confirms the order, record it using the Orders Sheet Tool.\n\n   - Order ID:\n     - Order ID is ORD-{{ $now.format('HHmmss') }}\n     - Use the SAME Order ID for all items in the same order.\n\n   - Order Time:\n     - Capture the CURRENT date and time using the system’s current current time/date: {{ $now.format('YYYY-MM-DD hh:mm A') }} at the moment the order is confirmed.\n     - Use the SAME Order Time for all items in the same order.\n\n   - For each ordered item:\n     - Create one row per item.\n     - Record:\n       - Order ID\n       - Order Time\n       - Customer Name\n       - Customer Phone\n       - Item Name\n       - Item Quantity\n       - Item Value (price × quantity)\n\n5. ORDER CONFIRMATION:\n   After recording the order, confirm in text only:\n   - Customer name\n   - Order ID\n   - Total amount\n   - Confirmation message\n\n   Example:\n   \"Thank you, Rohit Sharma! Your order has been confirmed.\n    Your Order ID is 1023 and the total amount is INR 420.\n    Your order will be prepared shortly. Let me know if you need anything else.\"\n\n6. COMPANY INFORMATION:\n   - If asked about hours, location, or policies, use the Company Info Vector Store.\n   - If not found, say:\n     \"I don’t have that information right now. Would you like me to connect you to a customer care executive?\"\n\n7. HUMAN SUPPORT:\n   - If you cannot help or are unsure, offer to connect to a human executive.\n\nBe friendly, simple, and natural—like a real pizza shop assistant.\n"
        }
      },
      "id": "c2b028ab-763a-482a-a79c-b152383a251a",
      "name": "Pizza Order Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3,
      "position": [
        640,
        0
      ]
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini"
        },
        "builtInTools": {},
        "options": {}
      },
      "id": "fe1deebe-62a6-417f-901e-6ef56afb127a",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        368,
        224
      ],
      "credentials": {
        "openAiApi": {
          "id": "ICwxUBbatsF2sDvy",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "d1f55c21-3548-4e50-b39f-4e50dd793a7d",
      "name": "OpenAI Embeddings",
      "type": "@n8n/n8n-nodes-langchain.embeddingsOpenAi",
      "typeVersion": 1.2,
      "position": [
        1040,
        368
      ],
      "credentials": {
        "openAiApi": {
          "id": "ICwxUBbatsF2sDvy",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Use this tool to check if a customer exists by phone number, retrieve customer details, or add new customers. The sheet has columns: Phone, Name, Address",
        "documentId": {
          "__rl": true,
          "value": "1Q9c7AoV6UCZDroJgh-kKK0Ahe0Hn8uExLK4eAlOXaFs",
          "mode": "list",
          "cachedResultName": "n8n Contacts",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Q9c7AoV6UCZDroJgh-kKK0Ahe0Hn8uExLK4eAlOXaFs/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 562956522,
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Q9c7AoV6UCZDroJgh-kKK0Ahe0Hn8uExLK4eAlOXaFs/edit#gid=562956522"
        },
        "options": {}
      },
      "id": "6068f898-181e-4911-aaa9-aaaec7d78ced",
      "name": "Customer_Info_Sheet_Tool",
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [
        688,
        400
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LOs2dbk9lby0NfDM",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "descriptionType": "manual",
        "toolDescription": "Use this tool to record pizza orders. The sheet has columns: Order ID, Order Time, Customer Name, Customer Phone, Item Name, Item Qty, Item Value. For multiple items in one order, use the SAME Order ID and Order Time for all rows.",
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1F0EPCxjtYdDtSi1bSaJ8ZokrYAmkIauYPagdUMeY0q0",
          "mode": "list",
          "cachedResultName": "n8n Pizza Orders",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1F0EPCxjtYdDtSi1bSaJ8ZokrYAmkIauYPagdUMeY0q0/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1F0EPCxjtYdDtSi1bSaJ8ZokrYAmkIauYPagdUMeY0q0/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Order ID": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Order_ID', ``, 'string') }}",
            "Order Time": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Order_Time', ``, 'string') }}",
            "Customer Name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Customer_Name', ``, 'string') }}",
            "Customer Phone": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Customer_Phone', ``, 'string') }}",
            "Item Name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Item_Name', ``, 'string') }}",
            "Item Qty": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Item_Qty', ``, 'string') }}",
            "Item Value": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Item_Value', ``, 'string') }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Order ID",
              "displayName": "Order ID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Order Time",
              "displayName": "Order Time",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Customer Name",
              "displayName": "Customer Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Customer Phone",
              "displayName": "Customer Phone",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Item Name",
              "displayName": "Item Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Item Qty",
              "displayName": "Item Qty",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Item Value",
              "displayName": "Item Value",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "id": "8b04aa14-333c-4be6-b689-403afde03323",
      "name": "Orders_Sheet_Tool",
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [
        544,
        352
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LOs2dbk9lby0NfDM",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "mode": "retrieve-as-tool",
        "toolDescription": "Search this knowledge base for company information like business hours, location, policies, delivery areas, and other company details",
        "memoryKey": {
          "__rl": true,
          "value": "vector_store_key",
          "mode": "list",
          "cachedResultName": "vector_store_key"
        }
      },
      "id": "405f6f8d-a2f7-4e69-9aec-2870646d314e",
      "name": "Company_Info_Vector_Store",
      "type": "@n8n/n8n-nodes-langchain.vectorStoreInMemory",
      "typeVersion": 1.3,
      "position": [
        960,
        208
      ]
    },
    {
      "parameters": {},
      "id": "0215ca2f-4d60-48d0-b66f-4bbf88b3af32",
      "name": "Calculator_Tool",
      "type": "@n8n/n8n-nodes-langchain.toolCalculator",
      "typeVersion": 1,
      "position": [
        1328,
        176
      ]
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1PH0axkqUVh-i4_nBeILRAiW0QzV3QKt0owg7XV3rLwU",
          "mode": "list",
          "cachedResultName": "n8n Pizza Menu",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1PH0axkqUVh-i4_nBeILRAiW0QzV3QKt0owg7XV3rLwU/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1PH0axkqUVh-i4_nBeILRAiW0QzV3QKt0owg7XV3rLwU/edit#gid=0"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [
        416,
        416
      ],
      "id": "27238bfd-3410-4cfb-a1f9-d706e15016c1",
      "name": "Get_Pizza_Menu",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LOs2dbk9lby0NfDM",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1Q9c7AoV6UCZDroJgh-kKK0Ahe0Hn8uExLK4eAlOXaFs",
          "mode": "list",
          "cachedResultName": "n8n Contacts",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Q9c7AoV6UCZDroJgh-kKK0Ahe0Hn8uExLK4eAlOXaFs/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 562956522,
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Q9c7AoV6UCZDroJgh-kKK0Ahe0Hn8uExLK4eAlOXaFs/edit#gid=562956522"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Name": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Name', ``, 'string') }}",
            "Email ID": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Email_ID', ``, 'string') }}",
            "Phone": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Phone', ``, 'string') }}",
            "Cust Address": "={{ /*n8n-auto-generated-fromAI-override*/ $fromAI('Cust_Address', ``, 'string') }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Name",
              "displayName": "Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Email ID",
              "displayName": "Email ID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Phone",
              "displayName": "Phone",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Cust Address",
              "displayName": "Cust Address",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheetsTool",
      "typeVersion": 4.7,
      "position": [
        848,
        368
      ],
      "id": "7c3790bf-7435-4f6b-b0a3-7c0e4019f714",
      "name": "Add_New_Customer",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "LOs2dbk9lby0NfDM",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "updates": [
          "message"
        ],
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.2,
      "position": [
        304,
        0
      ],
      "id": "fa35c6c5-55a1-4290-894c-ec318ef1b50c",
      "name": "Telegram Trigger",
      "webhookId": "8a1f280c-4ce3-472d-a5d7-459cd069b422",
      "credentials": {
        "telegramApi": {
          "id": "NFpPTqiHG1arwJ14",
          "name": "Telegram account"
        }
      }
    },
    {
      "parameters": {
        "sessionIdType": "customKey",
        "sessionKey": "={{ $json.message.chat.id }}"
      },
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.3,
      "position": [
        192,
        224
      ],
      "id": "94da5432-26c7-404f-8c23-36273b05e66c",
      "name": "Simple Memory"
    },
    {
      "parameters": {
        "chatId": "={{ $('Telegram Trigger').item.json.message.chat.id }}",
        "text": "={{ $json.output }}",
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        992,
        0
      ],
      "id": "3bc2910c-d0cc-4287-b2fd-32480cba7e57",
      "name": "Send a text message",
      "webhookId": "0be93614-84ce-4af9-8ab4-b9fb6d15e305",
      "credentials": {
        "telegramApi": {
          "id": "NFpPTqiHG1arwJ14",
          "name": "Telegram account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Pizza Order Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Embeddings": {
      "ai_embedding": [
        [
          {
            "node": "Company_Info_Vector_Store",
            "type": "ai_embedding",
            "index": 0
          }
        ]
      ]
    },
    "Customer_Info_Sheet_Tool": {
      "ai_tool": [
        [
          {
            "node": "Pizza Order Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Orders_Sheet_Tool": {
      "ai_tool": [
        [
          {
            "node": "Pizza Order Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Company_Info_Vector_Store": {
      "ai_tool": [
        [
          {
            "node": "Pizza Order Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Calculator_Tool": {
      "ai_tool": [
        [
          {
            "node": "Pizza Order Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Get_Pizza_Menu": {
      "ai_tool": [
        [
          {
            "node": "Pizza Order Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Add_New_Customer": {
      "ai_tool": [
        [
          {
            "node": "Pizza Order Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Pizza Order Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "Pizza Order Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Pizza Order Agent": {
      "main": [
        [
          {
            "node": "Send a text message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "55be0d07-df4b-4e80-9836-699952aeb9cf",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "3a43da28588548e21903e71cf1dc3ddd65c24bf0c62e7e4b77542ffe87ad79c6"
  },
  "id": "lIYU2P65MscgURpm",
  "tags": []
}